package com.heaboy.feedback.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heaboy.feedback.domain.vo.ClazzVO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.sql.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.heaboy.feedback.mapper.ClazzMapper;
import com.heaboy.feedback.domain.Clazz;
import com.heaboy.feedback.service.IClazzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
 * 班级Service业务层处理
 * 
 * @author heaboy
 * @date 2024-02-01
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements IClazzService
{
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 查询班级
     * 
     * @param id 班级主键
     * @return 班级
     */
    @Override
    public Clazz selectClazzById(Long id)
    {
        return clazzMapper.selectClazzById(id);
    }

    /**
     * 查询班级列表
     * 
     * @param clazz 班级
     * @return 班级
     */
    @Override
    public List<Clazz> selectClazzList(Clazz clazz)
    {
        return clazzMapper.selectClazzList(clazz);
    }

    /**
     * 新增班级
     * 
     * @param clazz 班级
     * @return 结果
     */
    @Override
    public int insertClazz(Clazz clazz)
    {
        clazz.setCreateTime(DateUtils.getNowDate());
        return clazzMapper.insertClazz(clazz);
    }

    /**
     * 修改班级
     * 
     * @param clazz 班级
     * @return 结果
     */
    @Override
    public int updateClazz(Clazz clazz)
    {
        clazz.setUpdateTime(DateUtils.getNowDate());
        return clazzMapper.updateClazz(clazz);
    }

    /**
     * 批量删除班级
     * 
     * @param ids 需要删除的班级主键
     * @return 结果
     */
    @Override
    public int deleteClazzByIds(Long[] ids)
    {
        return clazzMapper.deleteClazzByIds(ids);
    }

    /**
     * 删除班级信息
     * 
     * @param id 班级主键
     * @return 结果
     */
    @Override
    public int deleteClazzById(Long id)
    {
        return clazzMapper.deleteClazzById(id);
    }


    @Override
    public List<Clazz> selectUnallocatedList(ClazzVO clazz) {
        String sql = "select clazz_id from t_course_clazz where course_id= "+clazz.getCourseId();
        return baseMapper.selectList(new LambdaUpdateWrapper<Clazz>().notInSql(Clazz::getId, sql));
    }

    @Override
    public List<Clazz> selectallocatedList(ClazzVO clazz) {
        String sql = "select clazz_id from t_course_clazz where course_id= "+clazz.getCourseId();
        return baseMapper.selectList(new LambdaUpdateWrapper<Clazz>().inSql(Clazz::getId, sql));
    }
}
